from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-31 14:07:00.279250
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 31, Jan, 2021
Time: 14:07:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6695
Nobs: 188.000 HQIC: -46.5911
Log likelihood: 2127.73 FPE: 3.11527e-21
AIC: -47.2189 Det(Omega_mle): 1.95402e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.449225 0.143245 3.136 0.002
L1.Burgenland 0.116001 0.075294 1.541 0.123
L1.Kärnten -0.222959 0.061702 -3.613 0.000
L1.Niederösterreich 0.129689 0.172560 0.752 0.452
L1.Oberösterreich 0.227715 0.150852 1.510 0.131
L1.Salzburg 0.200436 0.079947 2.507 0.012
L1.Steiermark 0.093952 0.107737 0.872 0.383
L1.Tirol 0.159907 0.071973 2.222 0.026
L1.Vorarlberg -0.006944 0.065808 -0.106 0.916
L1.Wien -0.134423 0.144794 -0.928 0.353
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500912 0.177866 2.816 0.005
L1.Burgenland 0.015451 0.093491 0.165 0.869
L1.Kärnten 0.368265 0.076615 4.807 0.000
L1.Niederösterreich 0.115439 0.214266 0.539 0.590
L1.Oberösterreich -0.152359 0.187311 -0.813 0.416
L1.Salzburg 0.191785 0.099270 1.932 0.053
L1.Steiermark 0.240724 0.133776 1.799 0.072
L1.Tirol 0.138111 0.089368 1.545 0.122
L1.Vorarlberg 0.177374 0.081713 2.171 0.030
L1.Wien -0.583579 0.179789 -3.246 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299862 0.063771 4.702 0.000
L1.Burgenland 0.111692 0.033520 3.332 0.001
L1.Kärnten -0.024107 0.027469 -0.878 0.380
L1.Niederösterreich 0.065604 0.076821 0.854 0.393
L1.Oberösterreich 0.289066 0.067157 4.304 0.000
L1.Salzburg 0.006710 0.035591 0.189 0.850
L1.Steiermark -0.022568 0.047963 -0.471 0.638
L1.Tirol 0.093732 0.032041 2.925 0.003
L1.Vorarlberg 0.106947 0.029297 3.650 0.000
L1.Wien 0.078285 0.064460 1.214 0.225
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218376 0.072392 3.017 0.003
L1.Burgenland -0.009288 0.038051 -0.244 0.807
L1.Kärnten 0.022887 0.031183 0.734 0.463
L1.Niederösterreich 0.031958 0.087207 0.366 0.714
L1.Oberösterreich 0.388300 0.076236 5.093 0.000
L1.Salzburg 0.097079 0.040403 2.403 0.016
L1.Steiermark 0.182730 0.054447 3.356 0.001
L1.Tirol 0.041987 0.036373 1.154 0.248
L1.Vorarlberg 0.087734 0.033257 2.638 0.008
L1.Wien -0.064008 0.073175 -0.875 0.382
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.521056 0.144649 3.602 0.000
L1.Burgenland 0.075482 0.076032 0.993 0.321
L1.Kärnten 0.008785 0.062307 0.141 0.888
L1.Niederösterreich -0.010787 0.174252 -0.062 0.951
L1.Oberösterreich 0.155073 0.152331 1.018 0.309
L1.Salzburg 0.058724 0.080731 0.727 0.467
L1.Steiermark 0.110011 0.108794 1.011 0.312
L1.Tirol 0.211764 0.072679 2.914 0.004
L1.Vorarlberg 0.020833 0.066453 0.314 0.754
L1.Wien -0.139508 0.146213 -0.954 0.340
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161367 0.102605 1.573 0.116
L1.Burgenland -0.019770 0.053932 -0.367 0.714
L1.Kärnten -0.013035 0.044197 -0.295 0.768
L1.Niederösterreich 0.125359 0.123604 1.014 0.310
L1.Oberösterreich 0.395609 0.108054 3.661 0.000
L1.Salzburg -0.023264 0.057266 -0.406 0.685
L1.Steiermark -0.032618 0.077172 -0.423 0.673
L1.Tirol 0.190115 0.051554 3.688 0.000
L1.Vorarlberg 0.040544 0.047138 0.860 0.390
L1.Wien 0.183079 0.103715 1.765 0.078
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.230545 0.131048 1.759 0.079
L1.Burgenland 0.082492 0.068883 1.198 0.231
L1.Kärnten -0.043039 0.056449 -0.762 0.446
L1.Niederösterreich -0.023454 0.157868 -0.149 0.882
L1.Oberösterreich -0.104243 0.138008 -0.755 0.450
L1.Salzburg 0.032441 0.073140 0.444 0.657
L1.Steiermark 0.390600 0.098564 3.963 0.000
L1.Tirol 0.495158 0.065845 7.520 0.000
L1.Vorarlberg 0.162345 0.060205 2.697 0.007
L1.Wien -0.221014 0.132466 -1.668 0.095
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082214 0.159027 0.517 0.605
L1.Burgenland 0.031308 0.083589 0.375 0.708
L1.Kärnten -0.092618 0.068500 -1.352 0.176
L1.Niederösterreich 0.246661 0.191572 1.288 0.198
L1.Oberösterreich -0.000609 0.167472 -0.004 0.997
L1.Salzburg 0.233100 0.088756 2.626 0.009
L1.Steiermark 0.124462 0.119608 1.041 0.298
L1.Tirol 0.073112 0.079903 0.915 0.360
L1.Vorarlberg 0.041739 0.073058 0.571 0.568
L1.Wien 0.268137 0.160747 1.668 0.095
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.591076 0.083945 7.041 0.000
L1.Burgenland -0.020190 0.044124 -0.458 0.647
L1.Kärnten -0.003126 0.036159 -0.086 0.931
L1.Niederösterreich -0.039577 0.101125 -0.391 0.696
L1.Oberösterreich 0.285386 0.088403 3.228 0.001
L1.Salzburg 0.016994 0.046851 0.363 0.717
L1.Steiermark 0.014905 0.063137 0.236 0.813
L1.Tirol 0.080191 0.042178 1.901 0.057
L1.Vorarlberg 0.137117 0.038565 3.555 0.000
L1.Wien -0.058201 0.084853 -0.686 0.493
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.147633 0.023878 0.209273 0.257239 0.081059 0.081817 -0.053683 0.168357
Kärnten 0.147633 1.000000 0.019350 0.193919 0.164728 -0.114507 0.169046 0.024381 0.314092
Niederösterreich 0.023878 0.019350 1.000000 0.306071 0.080763 0.222003 0.138180 0.054111 0.368957
Oberösterreich 0.209273 0.193919 0.306071 1.000000 0.297273 0.304736 0.107754 0.080691 0.132603
Salzburg 0.257239 0.164728 0.080763 0.297273 1.000000 0.156498 0.052495 0.084245 -0.018123
Steiermark 0.081059 -0.114507 0.222003 0.304736 0.156498 1.000000 0.114125 0.093922 -0.090913
Tirol 0.081817 0.169046 0.138180 0.107754 0.052495 0.114125 1.000000 0.162195 0.151249
Vorarlberg -0.053683 0.024381 0.054111 0.080691 0.084245 0.093922 0.162195 1.000000 0.076624
Wien 0.168357 0.314092 0.368957 0.132603 -0.018123 -0.090913 0.151249 0.076624 1.000000